<?php
/*
 * Author:  Somnath Shinde- soma.shinde@gmail.com Mobile No:- 9423792564
 * 
 * Create Date: 
 * 
 * Version of MYSQL_to_PHP: 1.1
 * 
 * Ranzani( YZ'S );
 * 
 */
require_once 'Base/BaseEmployees.class.php';

Class Employees {

	public function  __construct() {
			if( true == isset( $_SERVER['connection'] ) ) {
				$this->connection = $_SERVER['connection'];
			}
	}

	
	/*******************************************************************************************
	******************************** Fetch Functions *******************************************
	*******************************************************************************************/

	public function fetchSql( $strSql ) {
		$result = $this->connection->RunQuery( $strSql );
		$arrobjEmployees = array();
		while( $row = $result->fetch_array( MYSQLI_ASSOC ) ) {
			$objEmployees = new BaseEmployees();
			$objEmployees->setId( ( true == isset( $row["id"] ) ) ? $row["id"] : 'NULL' );
			$objEmployees->setDepartmentId( ( true == isset( $row["department_id"] ) ) ? $row["department_id"] : 'NULL' );
			$objEmployees->setEmployeeTypeId( ( true == isset( $row["employee_type_id"] ) ) ? $row["employee_type_id"] : 'NULL' );
			$objEmployees->setFirstName( ( true == isset( $row["first_name"] ) ) ? $row["first_name"] : 'NULL' );
			$objEmployees->setMiddleName( ( true == isset( $row["middle_name"] ) ) ? $row["middle_name"] : 'NULL' );
			$objEmployees->setLastName( ( true == isset( $row["last_name"] ) ) ? $row["last_name"] : 'NULL' );
			$objEmployees->setPhoneNumber( ( true == isset( $row["phone_number"] ) ) ? $row["phone_number"] : 'NULL' );
			$objEmployees->setMobileNumber( ( true == isset( $row["mobile_number"] ) ) ? $row["mobile_number"] : 'NULL' );
			$objEmployees->setOfficeNumber( ( true == isset( $row["office_number"] ) ) ? $row["office_number"] : 'NULL' );
			$objEmployees->setEmailAddress( ( true == isset( $row["email_address"] ) ) ? $row["email_address"] : 'NULL' );
			$objEmployees->setAddressLine1( ( true == isset( $row["address_line1"] ) ) ? $row["address_line1"] : 'NULL' );
			$objEmployees->setAddressLine2( ( true == isset( $row["address_line2"] ) ) ? $row["address_line2"] : 'NULL' );
			$objEmployees->setArea( ( true == isset( $row["area"] ) ) ? $row["area"] : 'NULL' );
			$objEmployees->setCity( ( true == isset( $row["city"] ) ) ? $row["city"] : 'NULL' );
			$objEmployees->setPinCode( ( true == isset( $row["pin_code"] ) ) ? $row["pin_code"] : 'NULL' );
			$objEmployees->setCreatedBy( ( true == isset( $row["created_by"] ) ) ? $row["created_by"] : 'NULL' );
			$objEmployees->setCreatedOn( ( true == isset( $row["created_on"] ) ) ? $row["created_on"] : 'NULL' );
			$objEmployees->setUpdatedBy( ( true == isset( $row["updated_by"] ) ) ? $row["updated_by"] : 'NULL' );
			$objEmployees->setUpdatedOn( ( true == isset( $row["updated_on"] ) ) ? $row["updated_on"] : 'NULL' );
			array_push( $arrobjEmployees, $objEmployees );
		}
		return $arrobjEmployees;
	}
	public function fetchAllEmployees() {
		$result = $this->connection->RunQuery("SELECT * FROM EMPLOYEES");
		$arrobjEmployees = array();
		while( $row = $result->fetch_array( MYSQLI_ASSOC ) ) {
			$objEmployees = new BaseEmployees();
			$objEmployees->setId( ( true == isset( $row["id"] ) ) ? $row["id"] : 'NULL' );
			$objEmployees->setDepartmentId( ( true == isset( $row["department_id"] ) ) ? $row["department_id"] : 'NULL' );
			$objEmployees->setEmployeeTypeId( ( true == isset( $row["employee_type_id"] ) ) ? $row["employee_type_id"] : 'NULL' );
			$objEmployees->setFirstName( ( true == isset( $row["first_name"] ) ) ? $row["first_name"] : 'NULL' );
			$objEmployees->setMiddleName( ( true == isset( $row["middle_name"] ) ) ? $row["middle_name"] : 'NULL' );
			$objEmployees->setLastName( ( true == isset( $row["last_name"] ) ) ? $row["last_name"] : 'NULL' );
			$objEmployees->setPhoneNumber( ( true == isset( $row["phone_number"] ) ) ? $row["phone_number"] : 'NULL' );
			$objEmployees->setMobileNumber( ( true == isset( $row["mobile_number"] ) ) ? $row["mobile_number"] : 'NULL' );
			$objEmployees->setOfficeNumber( ( true == isset( $row["office_number"] ) ) ? $row["office_number"] : 'NULL' );
			$objEmployees->setEmailAddress( ( true == isset( $row["email_address"] ) ) ? $row["email_address"] : 'NULL' );
			$objEmployees->setAddressLine1( ( true == isset( $row["address_line1"] ) ) ? $row["address_line1"] : 'NULL' );
			$objEmployees->setAddressLine2( ( true == isset( $row["address_line2"] ) ) ? $row["address_line2"] : 'NULL' );
			$objEmployees->setArea( ( true == isset( $row["area"] ) ) ? $row["area"] : 'NULL' );
			$objEmployees->setCity( ( true == isset( $row["city"] ) ) ? $row["city"] : 'NULL' );
			$objEmployees->setPinCode( ( true == isset( $row["pin_code"] ) ) ? $row["pin_code"] : 'NULL' );
			$objEmployees->setCreatedBy( ( true == isset( $row["created_by"] ) ) ? $row["created_by"] : 'NULL' );
			$objEmployees->setCreatedOn( ( true == isset( $row["created_on"] ) ) ? $row["created_on"] : 'NULL' );
			$objEmployees->setUpdatedBy( ( true == isset( $row["updated_by"] ) ) ? $row["updated_by"] : 'NULL' );
			$objEmployees->setUpdatedOn( ( true == isset( $row["updated_on"] ) ) ? $row["updated_on"] : 'NULL' );
			array_push( $arrobjEmployees, $objEmployees);
		}
		return $arrobjEmployees;
	}
	public function fetchAllEmployeesByIds( $arrintIds ) {
		$result = $this->connection->RunQuery("SELECT * FROM EMPLOYEES WHERE id IN ( implode( "," $arrintIds ) " );
		$arrobjEmployees = array();
		while( $row = $result->fetch_array( MYSQLI_ASSOC ) ) {
			$objEmployees->setId( ( true == isset( $row["id"] ) ) ? $row["id"] : 'NULL' );
			$objEmployees->setDepartmentId( ( true == isset( $row["department_id"] ) ) ? $row["department_id"] : 'NULL' );
			$objEmployees->setEmployeeTypeId( ( true == isset( $row["employee_type_id"] ) ) ? $row["employee_type_id"] : 'NULL' );
			$objEmployees->setFirstName( ( true == isset( $row["first_name"] ) ) ? $row["first_name"] : 'NULL' );
			$objEmployees->setMiddleName( ( true == isset( $row["middle_name"] ) ) ? $row["middle_name"] : 'NULL' );
			$objEmployees->setLastName( ( true == isset( $row["last_name"] ) ) ? $row["last_name"] : 'NULL' );
			$objEmployees->setPhoneNumber( ( true == isset( $row["phone_number"] ) ) ? $row["phone_number"] : 'NULL' );
			$objEmployees->setMobileNumber( ( true == isset( $row["mobile_number"] ) ) ? $row["mobile_number"] : 'NULL' );
			$objEmployees->setOfficeNumber( ( true == isset( $row["office_number"] ) ) ? $row["office_number"] : 'NULL' );
			$objEmployees->setEmailAddress( ( true == isset( $row["email_address"] ) ) ? $row["email_address"] : 'NULL' );
			$objEmployees->setAddressLine1( ( true == isset( $row["address_line1"] ) ) ? $row["address_line1"] : 'NULL' );
			$objEmployees->setAddressLine2( ( true == isset( $row["address_line2"] ) ) ? $row["address_line2"] : 'NULL' );
			$objEmployees->setArea( ( true == isset( $row["area"] ) ) ? $row["area"] : 'NULL' );
			$objEmployees->setCity( ( true == isset( $row["city"] ) ) ? $row["city"] : 'NULL' );
			$objEmployees->setPinCode( ( true == isset( $row["pin_code"] ) ) ? $row["pin_code"] : 'NULL' );
			$objEmployees->setCreatedBy( ( true == isset( $row["created_by"] ) ) ? $row["created_by"] : 'NULL' );
			$objEmployees->setCreatedOn( ( true == isset( $row["created_on"] ) ) ? $row["created_on"] : 'NULL' );
			$objEmployees->setUpdatedBy( ( true == isset( $row["updated_by"] ) ) ? $row["updated_by"] : 'NULL' );
			$objEmployees->setUpdatedOn( ( true == isset( $row["updated_on"] ) ) ? $row["updated_on"] : 'NULL' );
			array_push( $arrobjEmployees, $objEmployees );
		}
		return $arrobjEmployees;
	}

	public function fetchEmployeesById( $intId ) {
		$result = $this->connection->RunQuery( "SELECT * FROM EMPLOYEES WHERE id = " . $intId );
			$objEmployees = NULL;
		while($row = $result->fetch_array( MYSQLI_ASSOC ) ) {
			$objEmployees = new BaseEmployees();
			$objEmployees->setId( ( true == isset( $row["id"] ) ) ? $row["id"] : 'NULL' );
			$objEmployees->setDepartmentId( ( true == isset( $row["department_id"] ) ) ? $row["department_id"] : 'NULL' );
			$objEmployees->setEmployeeTypeId( ( true == isset( $row["employee_type_id"] ) ) ? $row["employee_type_id"] : 'NULL' );
			$objEmployees->setFirstName( ( true == isset( $row["first_name"] ) ) ? $row["first_name"] : 'NULL' );
			$objEmployees->setMiddleName( ( true == isset( $row["middle_name"] ) ) ? $row["middle_name"] : 'NULL' );
			$objEmployees->setLastName( ( true == isset( $row["last_name"] ) ) ? $row["last_name"] : 'NULL' );
			$objEmployees->setPhoneNumber( ( true == isset( $row["phone_number"] ) ) ? $row["phone_number"] : 'NULL' );
			$objEmployees->setMobileNumber( ( true == isset( $row["mobile_number"] ) ) ? $row["mobile_number"] : 'NULL' );
			$objEmployees->setOfficeNumber( ( true == isset( $row["office_number"] ) ) ? $row["office_number"] : 'NULL' );
			$objEmployees->setEmailAddress( ( true == isset( $row["email_address"] ) ) ? $row["email_address"] : 'NULL' );
			$objEmployees->setAddressLine1( ( true == isset( $row["address_line1"] ) ) ? $row["address_line1"] : 'NULL' );
			$objEmployees->setAddressLine2( ( true == isset( $row["address_line2"] ) ) ? $row["address_line2"] : 'NULL' );
			$objEmployees->setArea( ( true == isset( $row["area"] ) ) ? $row["area"] : 'NULL' );
			$objEmployees->setCity( ( true == isset( $row["city"] ) ) ? $row["city"] : 'NULL' );
			$objEmployees->setPinCode( ( true == isset( $row["pin_code"] ) ) ? $row["pin_code"] : 'NULL' );
			$objEmployees->setCreatedBy( ( true == isset( $row["created_by"] ) ) ? $row["created_by"] : 'NULL' );
			$objEmployees->setCreatedOn( ( true == isset( $row["created_on"] ) ) ? $row["created_on"] : 'NULL' );
			$objEmployees->setUpdatedBy( ( true == isset( $row["updated_by"] ) ) ? $row["updated_by"] : 'NULL' );
			$objEmployees->setUpdatedOn( ( true == isset( $row["updated_on"] ) ) ? $row["updated_on"] : 'NULL' );
		}
		return $objEmployees;
	}

	public function GetKeysOrderBy($column, $order){
		$keys = array(); $i = 0;
		$result = $this->connection->RunQuery("SELECT id from employees order by $column $order");
			while($row = $result->fetch_array(MYSQLI_ASSOC)){
				$keys[$i] = $row["id"];
				$i++;
			}
	return $keys;
	}

	public function endEmployees(){
		$this->connection->CloseMysql();
	}

}